package com.click.app.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * @author Joel Chuca Condo
 * @date 16/06/2009
 */
@Entity 
@Table(name = "seam_storage")
public class SeamStorage extends BaseObject {

    private static final long serialVersionUID = 1L;
    private Long id;
    private int stock;
    private int stockLimit;
    private PantDesign pantDesign;
    private TradeMark tradeMark;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "id_seam_storage")
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="id_pant_design")
    public PantDesign getPantDesign() {
        return pantDesign;
    }

    public void setPantDesign(PantDesign pantDesign) {
        this.pantDesign = pantDesign;
    }

    @Column(name = "stock")
    public int getStock() {
        return stock;
    }

    public void setStock(int stock) {
        this.stock = stock;
    }

    @Column(name = "stock_limit")
    public int getStockLimit() {
        return stockLimit;
    }

    public void setStockLimit(int stockLimit) {
        this.stockLimit = stockLimit;
    }

    @ManyToOne( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
    @JoinColumn(name="id_trademark")
    public TradeMark getTradeMark() {
        return tradeMark;
    }

    public void setTradeMark(TradeMark tradeMark) {
        this.tradeMark = tradeMark;
    }

    @Transient
    public String getDescription(){
        return pantDesign.getDatas()+" ["+tradeMark.getName()+"]";
    }

    @Transient
    public void incrementStock(int value){
        stock += value;
    }

    @Transient
    public void decrementStock(int value){
        stock-=value;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof SeamStorage)) {
            return false;
        }
        SeamStorage other = (SeamStorage) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.click.app.model.SeamStorage[id=" + id + "]";
    }
}
